Dim S1, N, XX, Num, I, M, S, T1, Prime, A, even, odd, sub1, XX1, Fsub1 As Double
Dim Cal, DateTime1, DateTime2 As String

Private Sub Command1_Click()

Fsub1 = Val(Text7.Text)

Open "Prime arit Finder1.doc" For Output As #1

Open "Prime arit Finder2.doc" For Output As #2

T1 = Timer

Cal = "dddd, mmmm dd yyyy hh:mm:ss AM/PM"

DateTime1 = Format(Now, Cal)

S1 = Val(Text1.Text)
N = Val(Text2.Text)

Text1.Text = Format(S1, "#,###")
Text2.Text = Format(N, "#,###")

XX = 0
XX1 = 0

Num = S1
GoTo 7
6
Num = Num + 1
7
Do While Num <> N

If Num >= 1 And Num <= 10 Then
GoTo 3
End If

If Num Mod 2 = 0 Or Num Mod 5 = 0 Then
GoTo 6
End If

3
Text5.Refresh
Text6.Refresh

Prime = 1
A = Sqr(Num)

For I = 2 To Int(A)

If Num Mod I = 0 Then
Prime = 0

GoTo 5

End If
Next I

5

If Prime = 1 And Num >= 2 Then

XX = XX + 1

If XX Mod 2 <> 0 Then

odd = Num

If even <> 0 Then

sub1 = odd - even

If Fsub1 = sub1 Then

XX1 = XX1 + 1

Text5.Text = Trim(Format(XX1, "#,###"))

Text6.Text = Trim(Format(even, "#,###"))

Text8.Text = Trim(Format(even + Fsub1, "#,###"))

Text8.Refresh

Print #1, Format(even, "#,###") & " ";

Print #2, Format(even + Fsub1, "#,###") & " ";

End If

End If

End If

If XX Mod 2 = 0 Then

even = Num

sub1 = even - odd

If Fsub1 = sub1 Then

XX1 = XX1 + 1

Text5.Text = Trim(Format(XX1, "#,###"))

Text6.Text = Trim(Format(odd, "#,###"))

Text8.Text = Trim(Format(odd + Fsub1, "#,###"))

Text8.Refresh

Print #1, Format(odd, "#,###") & " ";

Print #2, Format(odd + Fsub1, "#,###") & " ";

End If

End If
   
End If

Num = Num + 1

Text4.Text = "Number of Prime Numbers from " & Format(S1, "#,###") & " to " & Format(N, "#,###") & " is " & Format(XX1, "#,###") & "."
Text4.Refresh

DateTime2 = Format(Now, Cal)

M = Val(Left(Right(DateTime2, 8), 2)) - Val(Left(Right(DateTime1, 8), 2))
S = Val(Left(Right(DateTime2, 5), 2)) - Val(Left(Right(DateTime1, 5), 2))

T1 = Timer - T1
T1 = Int((T1 - Int(T1)) * 100)

If T1 = 0 Then
T1 = 1
End If

If S < 0 Then
S = S + 60
M = M - 1
End If

If M < 0 Then
M = M + 60
End If

Text3.Text = "Minutes : Seconds . >Sec = " & M & " : " & S & " . " & T1
Text3.Refresh

Loop

Print #1,
Print #1,

Print #1, "Prime Number Arit Finder is " & Text7.Text

Print #1,

Print #1, Text4.Text

Print #1,

Print #1, Text3.Text

Close #1

Print #2,
Print #2,

Print #2, "Prime Number Arit Finder is " & Text8.Text

Print #2,

Print #2, Text4.Text

Print #2,

Print #2, Text3.Text

Close #2

End Sub


Private Sub Command2_Click()

Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
Text7.Text = ""
Text8.Text = ""

End Sub

Private Sub Form_Load()

Text1.Text = 100000

Text2.Text = 999999

Text7.Text = 66

End Sub
